package com.yuanian.ecsplus.bean.vo;

import com.yuanian.ecsplus.cache.CacheManager;
import com.yuanian.ecsplus.meta.vo.MetaVo;
import com.yuanian.ecsplus.model.vo.BaseVoModel;
import com.yuanian.ecsplus.platform.PlatformSupport;
import com.yuanian.ecsplus.platform.SpringContextBean;
import com.yuanian.ecsplus.session.FullDataSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 包含了字段定义的查询方式,参考customFieldBeanVo
 * @param <T>
 */
public class FullDataModel<T extends BaseVoModel> implements FullDataSession<T> {

    //查询实体类字节
    private Class<T> clz;

    //平台的支撑类
    private PlatformSupport platformSupport;

    public FullDataModel(Class<T> clz) {
        this.clz = clz;
        this.platformSupport = SpringContextBean.getBean(PlatformSupport.class);
    }

    /**
     * 创建一个带有默认值的map
     * @return
     */
    public Map createMapOne() {
        return createMapOne(new HashMap());
    }


    /**
     * 创建一个带有默认值的map,并提供了初始化数据
     * @return
     */
    public Map createMapOne(Map initData) {
        MetaVo<T> metaEntity = CacheManager.getInstance().getMetaVo(clz);
        return metaEntity.findFieldListMap(initData, true);
    }

    /**
     * 创建一个带有默认值的map
     * @param initData
     * @param insertFlag 是否插入数据库
     * @return
     */
    public T createOne(Map initData, boolean insertFlag) {
        MetaVo<T> metaEntity = CacheManager.getInstance().getMetaVo(clz);
        return metaEntity.findFieldList(initData, insertFlag);
    }

    /**
     * 创建一个带有默认值的map
     * @param insertFlag 是否插入数据库
     * @return
     */
    public T createOne(boolean insertFlag) {
        return createOne(new HashMap<>(), insertFlag);
    }

}
